﻿Ext.Loader.setConfig({enabled: true});
Ext.Loader.setPath('Ext.ux', ctx+'/resources/extjs/ux');
Ext.require([
	'Ext.ux.form.MultiSelect',
	'Ext.ux.form.ItemSelector'       
]);

Ext.define('HIT.view.SetUserRightsAddPanel', {
	extend: 'Ext.form.Panel',
	alias: 'widget.setuserrightsaddpanel',
	
    height:400,
    width:600,
    resizable:false,
    plain: true,
    modal : true,
    overlapHeader: false,
    preventHeader: true,
    title: Share.T('增加用户权限'),
    
    initComponent: function() {
        var me = this;
        
        Ext.apply(Ext.form.VTypes, {
        	confirmpsw : function(val, field) {
        		if (field.confirmTo) {
        			var pwd = Ext.getCmp(field.confirmTo);
        			return (val == pwd.getValue());
        		}
        		return true;
        	}
        });
        Ext.apply(Ext.form.VTypes, {
            daterange : function(val, field) {
                var date = field.parseDate(val);
                // We need to force the picker to update values to
                // recaluate the disabled dates display
                var dispUpd = function(picker) {
                    var ad = picker.activeDate;
                    picker.activeDate = null;
                    picker.update(ad);
                };

                if (field.startDateField) {
                    var sd = Ext.getCmp(field.startDateField);
                    sd.maxValue = date;
                    if (sd.menu && sd.menu.picker) {
                        sd.menu.picker.maxDate = date;
                        dispUpd(sd.menu.picker);
                    }
                }
                else if (field.endDateField) {
                    var ed = Ext.getCmp(field.endDateField);
                    ed.minValue = date;
                    if (ed.menu && ed.menu.picker) {
                        ed.menu.picker.minDate = date;
                        dispUpd(ed.menu.picker);
                    }
                }                        
                return true;
            }
        });

        Ext.applyIf(me, {
            items: [ {
            	xtype: 'hiddenfield',
            	id: 'functionId',
            	value: 0
            }, {
            	xtype: 'hiddenfield',
                id: 'userId'
            }, {
                xtype: 'textfield',
                anchor: '100%',
                x : 10,
                fieldLabel: Share.T('登录名'),
                id: 'loginName',
                margin: '10 50 10',
                width: 300,
                maxLength: 50,
                allowBlank:false,
                blankText:Share.T('登录名不能为空'),
                msgTarget  : 'side'
            }, {
                xtype: 'textfield',
                anchor: '100%',
                id: 'userName',
                maxLength: 50,
                fieldLabel: Share.T('用户名'),
                margin: '10 50 10',
                width: 300,
                allowBlank:false,
                blankText:Share.T('用户名不能为空'),
                msgTarget  : 'side'
            }, {
                xtype: 'textfield',
                anchor: '100%',
                id:'password',
                maxLength: 255,
                inputType: 'password',
                fieldLabel: Share.T('密码'),
                allowBlank:false,
                blankText:Share.T('密码不能为空'),
                msgTarget  : 'side',
                margin: '10 50 10',
                width: 300
            }, {
                xtype: 'textfield',
                anchor: '100%',
                id:'confirmpassword',
                maxLength: 255,
                inputType: 'password',
                vtype:'confirmpsw',
                vtypeText:Share.T("两次密码不一致！"),
                msgTarget  : 'side',
                confirmTo:"password",
                fieldLabel: Share.T('确认密码'),
                allowBlank:false,
                blankText:Share.T('确认密码不能为空'),
                margin: '10 50 10',
                width: 300
            }, {
                xtype: 'textfield',
                anchor: '100%',
                id: 'email',
                maxLength: 50,
                fieldLabel: 'E-mail',
                vtype: 'email',
                vtypeText:Share.T("邮箱格式不正确！"),
                msgTarget  : 'side',
                allowBlank:false,
                blankText:Share.T('邮箱不能为空'),
                msgTarget  : 'side',
                margin: '10 50 10',
                width: 300
            }, {
                xtype: 'combobox',
                anchor: '100%',
                fieldLabel: Share.T('公司'),
                id: 'company',
                margin: '10 50 10',
                width: 300,                          
                editable: false,
                queryMode: 'local',
                store:new Ext.data.Store({
					proxy: { 
    	                type: 'ajax', 
    	                url : ctx + '/getCompanyList',
    	                params:{},
    	                reader: { 
    	                    type: 'json', 
    	                    totalProperty: '', 
    	                    root: '' 
    	                } 
	     	        },
	     	        fields:['companyName','companyId'], 
	     	        autoLoad:true 
                }),
                listeners:{
                    beforequery : function(qe) {
                        this.store.load();
                    }
                },
		        valueField   : 'companyId',
		        displayField : 'companyName'
            }, {
                xtype:'itemselector',
                anchor: '100%',
                name:'itemselector',
                autoScroll:true,
                height:185,
                fieldLabel: Share.T('角色'),
                margin: '10 50 10',
                id: 'role',                   
                imagePath: ctx+'/resources/extjs/ux/images/',
                listeners:{
                    beforequery : function(qe) {
                        this.store.load();
                    }
                },
                store:new Ext.data.Store({
 					proxy: { 
     	                type: 'ajax', 
     	                url : ctx + '/getRoleList',
     	                params:{},
     	                reader: {
     	                    type: 'json', 
     	                    totalProperty: '', 
     	                    root: '' 
     	                } 
	     	        }, 
	     	        fields:['text','value'], 
	     	        autoLoad:true ,
	     	        sortInfo: {
	                     field: 'value',
	                     direction: 'ASC'
	                 }
                }),
                displayField: 'text',
                valueField: 'value',
                value: [],
                allowBlank: false,                
                msgTarget: 'side',
                blankText  : Share.T('此项目不能为空。'),
                fromTitle: Share.T('待选择'),
                toTitle: Share.T('已选择' )                  
            } ]
        });
        me.callParent(arguments);
    }
});